home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 May / SGI IRIX 6.5 Applications 2004 May.iso / dev / java_dev.idb / usr / java / include / monitor.h.z / monitor.h
Encoding:
C/C++ Source or Header  |  2000-05-20  |  5.0 KB  |  164 lines

  1. /*
  2.  * @(#)monitor.h    1.35 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. /*
  16.  * Monitor interface
  17.  */
  18.  
  19. #ifndef    _MONITOR_H_
  20. #define    _MONITOR_H_
  21.  
  22. #include "sys_api.h"
  23.  
  24. /*
  25.  * Used by the monitor caching machanism to mark monitors as being
  26.  * in-use.
  27.  */
  28. #define MON_LOCAL_CACHE_REF        (1 << 0)
  29.  
  30. /*
  31.  * The monitor data structure:
  32.  *
  33.  * The use_count field counts the number of createMonitor calls yet
  34.  * unmatched by monitorExit calls; that is, it is a count of outstanding
  35.  * monitor entries of all threads regardless of whether those threads
  36.  * own the monitor or are waiting on it.
  37.  *
  38.  * Note that because the mid[] array will hold the system-specific
  39.  * sys_mon_t, it needs to start on a four-byte boundary lest the fields
  40.  * of the sys_mon_t aren't properly aligned.  Otherwise the flags field
  41.  * would be shorter than a long.
  42.  */
  43. typedef struct monitor_t {
  44.     unsigned int    key;        /* Monitor hash key */
  45.     struct monitor_t   *next;
  46.     char        mid[1];        /* The sys_mon_t */
  47. } monitor_t, *MID;
  48.  
  49. /* A macro for accessing the sys_mon_t from the monitor_t */
  50. #define sysmon(m)   (*(sys_mon_t *) m->mid)
  51.  
  52. typedef struct reg_mon_t {
  53.     sys_mon_t *mid;
  54.     char *name;
  55.     struct reg_mon_t *next;
  56. } reg_mon_t;
  57.  
  58. /*
  59.  * Macros
  60.  */
  61. #define MID_NULL         ((MID) 0)
  62. #define TIMEOUT_INFINITY    -1
  63.  
  64. /*
  65.  * Support for the monitor registry
  66.  */
  67. extern sys_mon_t *_registry_lock;
  68.  
  69. #define REGISTRY_LOCK_INIT()    monitorRegister(_registry_lock, \
  70.                         "Monitor registry")
  71. #define REGISTRY_LOCK()          sysMonitorEnter(_registry_lock)
  72. #define REGISTRY_LOCKED()    sysMonitorEntered(_registry_lock)
  73. #define REGISTRY_UNLOCK()    sysMonitorExit(_registry_lock)
  74.  
  75. /*
  76.  * External routines.
  77.  */
  78.  
  79. /*
  80.  * Synchronization interface
  81.  */
  82. void monitorInit(monitor_t *mon);
  83. void monitorCacheInit(void);
  84. void monitorEnter(unsigned int);
  85. void monitorExit(unsigned int);
  86. void monitorExit_native(unsigned int);
  87. void monitorWait(unsigned int, int);
  88. void monitorNotify(unsigned int);
  89. void monitorNotifyAll(unsigned int);
  90.  
  91. /* Registry of static monitors */
  92. extern reg_mon_t *MonitorRegistry;
  93. void awt_lock_enter(void);
  94. void awt_lock_exit(void);
  95. void awt_lock_wait(int millis);
  96. void awt_lock_notify(void);
  97. void awt_lock_notify_all(void);
  98. sys_thread_t *awt_lock_owner(void);
  99.  
  100.  
  101. void monitorRegistryInit(void);
  102. void monitorRegister(sys_mon_t *, char *);
  103. void monitorUnregister(sys_mon_t *);
  104. void registeredEnumerate(void (*)(reg_mon_t *, void *), void *); 
  105. void registeredEnumerate_unlocked(void (*)(reg_mon_t *, void *), void *); 
  106.  
  107.  
  108. /*
  109.  * Random non-local locks without obviously better homes 
  110.  */
  111.  
  112. /* The class loading lock */
  113.  
  114. extern sys_mon_t *_loadclass_lock;
  115. #define LOADCLASS_LOCK_INIT() \
  116.     monitorRegister(_loadclass_lock, "Class loading lock")
  117. #define LOADCLASS_LOCK()     sysMonitorEnter(_loadclass_lock)
  118. #define LOADCLASS_LOCKED()   sysMonitorEntered(_loadclass_lock)
  119. #define LOADCLASS_UNLOCK()   sysMonitorExit(_loadclass_lock)
  120.  
  121. /* The global class table (binclasses) lock */
  122. extern sys_mon_t *_binclass_lock;
  123. #define BINCLASS_LOCK_INIT() monitorRegister(_binclass_lock, "BinClass lock")
  124. #define BINCLASS_LOCK()         sysMonitorEnter(_binclass_lock)
  125. #define BINCLASS_LOCKED()    sysMonitorEntered(_binclass_lock)
  126. #define BINCLASS_UNLOCK()    sysMonitorExit(_binclass_lock)
  127.  
  128. /* Locks on the interned string hash table */
  129.  
  130. extern sys_mon_t *_stringhash_lock;
  131. #define STRINGHASH_INIT()    monitorRegister(_stringhash_lock, \
  132.                          "String intern lock")
  133. #define STRINGHASH_LOCK()    sysMonitorEnter(_stringhash_lock)
  134. #define STRINGHASH_LOCKED()  sysMonitorEntered(_stringhash_lock)
  135. #define STRINGHASH_UNLOCK()  sysMonitorExit(_stringhash_lock)
  136.  
  137. /* Locks on the method info (name and signature) hash table */
  138.  
  139. extern sys_mon_t *_nametypehash_lock;
  140. #define NAMETYPEHASH_INIT()   monitorRegister(_nametypehash_lock, \
  141.                           "Name and type hash table lock")
  142. #define NAMETYPEHASH_LOCK()   sysMonitorEnter(_nametypehash_lock)
  143. #define NAMETYPEHASH_LOCKED() sysMonitorEntered(_nametypehash_lock)
  144. #define NAMETYPEHASH_UNLOCK() sysMonitorExit(_nametypehash_lock)
  145.  
  146. /* JNI global reference locks */
  147.  
  148. extern sys_mon_t *_globalref_lock;
  149. #define GLOBALREF_LOCK_INIT() \
  150.           monitorRegister(_globalref_lock, "JNI global reference lock")
  151. #define GLOBALREF_LOCK()        sysMonitorEnter(_globalref_lock)
  152. #define GLOBALREF_LOCKED()        sysMonitorEntered(_globalref_lock)
  153. #define GLOBALREF_UNLOCK()        sysMonitorExit(_globalref_lock)
  154.  
  155. /*  reentrant gethostbyname/gethostbyaddr (gethostbyxxxx_r) locks */
  156.  
  157. extern sys_mon_t _hostent_lock;
  158. #define HOSTENT_LOCK_INIT() monitorRegister(&_hostent_lock, "hostent lock");
  159. #define HOSTENT_LOCK()      sysMonitorEnter(&_hostent_lock)
  160. #define HOSTENT_UNLOCK()    sysMonitorExit(&_hostent_lock)
  161. #define HOSTENT_LOCKED()    sysMonitorEntered(&_hostent_lock)
  162.  
  163. #endif    /* !_MONITOR_H_ */
  164.